//
//  RoomEditCell.m
//  AILock
//
//  Created by 谭亚明 on 2020/7/8.
//  Copyright © 2020 tym. All rights reserved.
//

#import "RoomEditCell.h"
#import "Masonry.h"
#import "UIImageView+YPImage.h"
@interface RoomEditCell ()

@property(nonatomic,weak) UIImageView *equmentImage;
@property(nonatomic,weak) TYMLabel *nameLab;
@property(nonatomic,weak) TYMButton *rightBtn;
@end

@implementation RoomEditCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initUI];
    }
    return self;
}

-(void)initUI{
    
    UIImageView *head = [[UIImageView alloc] init];
    head.image = [UIImage imageNamed:@"icon_tx2"];
    head.contentMode = UIViewContentModeScaleAspectFit;
    [self.contentView addSubview:head];
    head.backgroundColor = rgba(246, 246, 246);
    self.equmentImage = head;
    
    TYMLabel *lab = [TYMLabel lb_text:@"sdfsfs" font:Font_Medium(14) color:rgba(74, 74, 74)];
    [self.contentView addSubview:lab];
    self.nameLab  = lab;
    
    TYMButton *btn = [TYMButton btn_Image:@"icon_delete1"];
    [self.contentView addSubview:btn];
    self.rightBtn = btn;
    [btn addTarget:self action:@selector(deleteActtion:) forControlEvents:UIControlEventTouchUpInside];
    [self.equmentImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(98, 84));
        make.top.equalTo(self.contentView);
        make.left.mas_equalTo(0);
    }];
    
    [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.equmentImage.mas_right).offset(10);
        make.centerY.equalTo(self.equmentImage);
    }];
    
    [self.rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.equmentImage);
        make.width.height.equalTo(@(20));
        make.right.mas_equalTo(@(-15));
    }];
    
}

//删除操作
-(void)deleteActtion:(id)sender{
    
    if (self.deleteEqumentBlock) {
        self.deleteEqumentBlock();
    }
}

-(void)setEqumentModel:(EquipmentModel  *)equmentModel{
    
    _nameLab.text = equmentModel.equipmentName;
    [_equmentImage yp_setImageUlr:equmentModel. getEquipmentImage];
}


+(NSString*)identifier{
    return @"RoomEditCell";
}

+(CGFloat)cellForHeight{
    return 84;
}

@end
